package com.aftersale.platform.service;

import com.aftersale.platform.entity.Announcement;
import com.aftersale.platform.mapper.AnnouncementMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    public List<Announcement> findAll() {
        return announcementMapper.findAll();
    }

    public Announcement findById(Integer id) {
        return announcementMapper.findById(id);
    }

    public void save(Announcement announcement) {
        if (announcement.getPublishDate() == null) {
            announcement.setPublishDate(LocalDate.now()); // 默认发布日期为当前
        }
        announcementMapper.save(announcement);
    }

    public void update(Announcement announcement) {
        announcementMapper.update(announcement);
    }

    public void delete(Integer id) {
        announcementMapper.delete(id);
    }
}